VERSION 5.00
Begin VB.Form frmImposta 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Imposta Connessione"
   ClientHeight    =   2835
   ClientLeft      =   45
   ClientTop       =   345
   ClientWidth     =   3630
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2835
   ScaleWidth      =   3630
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton cmdEsci 
      Cancel          =   -1  'True
      Caption         =   "&Annulla"
      Height          =   255
      Left            =   120
      TabIndex        =   10
      Top             =   2520
      Width           =   3375
   End
   Begin VB.CommandButton cmdImposta 
      Caption         =   "&Imposta Connessione"
      Height          =   255
      Left            =   120
      TabIndex        =   9
      Top             =   2160
      Visible         =   0   'False
      Width           =   3375
   End
   Begin VB.CommandButton cmdConnetti 
      Caption         =   "&Connetti"
      Default         =   -1  'True
      Height          =   255
      Left            =   2160
      TabIndex        =   8
      Top             =   1380
      Width           =   1335
   End
   Begin VB.ComboBox lstDB 
      Height          =   315
      Left            =   1440
      TabIndex        =   6
      ToolTipText     =   "Select database from list"
      Top             =   1680
      Width           =   2055
   End
   Begin VB.TextBox txtLogin 
      Height          =   315
      Left            =   1440
      TabIndex        =   2
      ToolTipText     =   "Enter Login"
      Top             =   600
      Width           =   2055
   End
   Begin VB.TextBox txtServer 
      Height          =   315
      Left            =   1440
      TabIndex        =   1
      ToolTipText     =   "Enter Server name"
      Top             =   240
      Width           =   2055
   End
   Begin VB.TextBox txtPassword 
      Height          =   315
      IMEMode         =   3  'DISABLE
      Left            =   1440
      PasswordChar    =   "*"
      TabIndex        =   0
      ToolTipText     =   "Enter Password"
      Top             =   960
      Width           =   2055
   End
   Begin VB.Label Label6 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Select Database"
      Height          =   195
      Left            =   120
      TabIndex        =   7
      Top             =   1680
      Width           =   1185
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Password"
      Height          =   195
      Left            =   120
      TabIndex        =   5
      Top             =   960
      Width           =   690
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Login"
      Height          =   195
      Left            =   120
      TabIndex        =   4
      Top             =   600
      Width           =   390
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Server Name"
      Height          =   195
      Left            =   120
      TabIndex        =   3
      Top             =   240
      Width           =   930
   End
End
Attribute VB_Name = "frmImposta"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Cartoline;Data Source=daniele"
Private Sub cmdConnetti_Click()
    On Error GoTo errore
    Dim DB As SQLDMO.Database
    Dim SqlSrv As SQLServer
    If Trim$(txtServer.Text) = "" Or Trim$(txtLogin.Text) = "" Then
        MsgBox "Inserisci Nome del server e Login", vbCritical
        txtServer.SetFocus
        Exit Sub
    End If
    Set SqlSrv = New SQLServer
    Set DB = New SQLDMO.Database
    lstDB.Clear
    SqlSrv.Connect Trim$(txtServer.Text), Trim$(txtLogin.Text), Trim$(txtPassword.Text)
    For Each DB In SqlSrv.Databases
        If DB.Status <> SQLDMODBStat_Inaccessible Then
            lstDB.AddItem DB.Name
        End If
    Next
    cmdImposta.Visible = True
    cmdImposta.Default = True
    Exit Sub
errore:
    Err.Source = cmdConnetti
    GestioneErrore "Impossibile connettersi"
End Sub
Private Sub cmdEsci_Click()
    Unload Me
End Sub
Private Sub cmdImposta_Click()
    On Error GoTo errore
    Dim Fs As Scripting.FileSystemObject
    Dim A
    If txtServer.Text = vbNullString Then
        MsgBox "Inserisci un nome di server"
        Exit Sub
    ElseIf txtLogin.Text = vbNullString Then
        MsgBox "Inserisci un nome di login"
        Exit Sub
    ElseIf lstDB.ListIndex = -1 Then
        MsgBox "Seleziona un database"
        Exit Sub
    End If
    cnString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & Trim(txtLogin.Text)
    cnString = cnString & ";Password=" & Trim(txtPassword.Text)
    cnString = cnString & ";Initial Catalog=" & lstDB.List(lstDB.ListIndex)
    cnString = cnString & ";Data Source=" & Trim$(txtServer.Text)
    Set Fs = New Scripting.FileSystemObject
    Set A = Fs.CreateTextFile(App.Path & "\Setting.Dat", True, False)
    A.WriteLine cnString
    A.Close
    Set Fs = Nothing
    Set A = Nothing
    Unload frmImposta
    Unload frmSplash
    Call Main
    Exit Sub
errore:
    Err.Source = "CmdImposta"
    GestioneErrore "Impossibile salvare la stringa di connessione"
End Sub
Private Sub Form_Unload(Cancel As Integer)
    cnString = vbNullString
    Dim i As Integer
    While Forms.Count > 1
        i = 0
        While Forms(i).Caption = Me.Caption
            i = i + 1
        Wend
        Unload Forms(i)
    Wend
    Unload Me
End Sub
